/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Angelo
 */
public class Owner {

    private static Owner s = null;
    private String owner;
    private List<Table> table_list;

    public static Owner getInstance() {
        if (s == null) {
            return new Owner();
        }
        return s;
    }

    public Owner() {
    }

    public Owner(String owner) {
        this.owner = owner;
        this.table_list = new ArrayList<Table>();
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public List<Table> getTable_list() {
        return table_list;
    }
    
    public void setTable_list(List<Table> table_list) {
        this.table_list = table_list;
    }    

    public Table getTable(String table_name) {
        for (Table t : table_list) {
            if (t.getTable_name().equals(table_name)) {
                return t;
            }
        }
        return null;
    }
    
    public void updateTable(String table, int records, double growth, int retention) throws Exception {
        Table t = getTable(table);
        if (t == null) {
            throw new Exception("Table " + table + " não encontrada!");
        }
        t.setPar_records(records);
        t.setPar_growth_rate(growth);
        t.setPar_retention_time(retention);
    }    

    public void updateColumn(String table, String column, Double avgSize, Double percNull) throws Exception {
        Table t = getTable(table);
        if (t == null) {
            throw new Exception("Table " + table + " não encontrada!");
        }
        t.updateColumn(column, avgSize, percNull);
    }

}
